package com.qq.controller;

import com.qq.dto.ActionResult;
import com.qq.pojo.CarCity;
import com.qq.service.CarCityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
public class CarCityController {

    @Autowired(required = false)
    private CarCityService carCityService;
    @RequestMapping(value = "/getCities",method = RequestMethod.GET)
    public ActionResult findCityByPid(int pid){
//        ArrayList<Object> cities = new ArrayList<>();
//        cities.add(new CarCity(1,"上海",0));
//        cities.add(new CarCity(2,"广州",0));
//        cities.add(new CarCity(3,"深圳",0));
        List<CarCity> cities = carCityService.selectCitiesByPid(pid);


        ActionResult result = new ActionResult(200,null,cities);
        return result;
    }

    @GetMapping("/getCityById")
    public ActionResult getCityById(int getid, int backid){
        CarCity city = carCityService.getCityById(getid);
        CarCity city2 = carCityService.getCityById(backid);
        CarCity cities[] = {city,city2};

        ActionResult actionResult = new ActionResult(200, null, cities);
        return actionResult;
    }
}
